﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}
@model TaoPortal.Areas.Admin.Models.UserModel
<ul class="breadcrumb" style="margin-bottom: 7px;">
    <li><a href="#">首页</a> <span class="divider">/</span></li>
    <li><a href="#">用户管理</a> <span class="divider">/</span></li>
    <li class="active">角色管理</li>
</ul>
<div style="text-align: right; margin-bottom: 5px;">
    <button class="button button-small button-primary" id="btnCreate" type="button">新建</button>
</div>
<div id="grid">
</div>
<script type="text/javascript">
    var Grid = BUI.Grid,
    Store = BUI.Data.Store,
    columns = [
      { title: '角色名称', width: 200, sortable: false, dataIndex: 'RoleName' },
      { title: '描述', width: 200, sortable: false, dataIndex: 'RoleDesc' },
      { title: '角色类型', width: 200, sortable: false, dataIndex: 'RoleType' },
      {
          title: '操作', width: 110, sortable: false, dataIndex: 'ID',
          renderer: function (value, obj) {
              return '<span class="grid-command" onclick="EditPage(\'' + value + '\')">权限设置</span><span class="grid-command" onclick="EditPage(\'' + value + '\')">编辑</span><span class="grid-command" onclick="DeletePage(\'' + value + '\')" >删除</span>';
          }
      }
    ];
    //加载列表
    var store = new Store({
        url: '/Admin/RoleManage/AjaxGetList',
        proxy: {
            limitParam: 'pageSize',
            method: 'post'
        },
        autoLoad: true,
        pageSize: 10
    }),
    grid = new Grid.Grid({
        render: '#grid',
        loadMask: true,
        forceFit: true,
        plugins: [Grid.Plugins.AutoFit],
        columns: columns,
        store: store,
        bbar: {
            pagingBar: true
        }
    });
    grid.render();

    var Overlay = BUI.Overlay
    var dialog = null;
    //新建页面
    $('#btnCreate').click(function () {
        dialog = new Overlay.Dialog({
            title: '角色管理->新建页面',
            width: 530,
            closeAction: 'destroy',
            height: 310,
            buttons: [],
            bodyStyle: { 'padding': '0px' },
            bodyContent: '<iframe frameborder="0" style="width:520px;height:248px" src="/Admin/RoleManage/AddRole"></iframe>'
        });
        dialog.show();
    })
    function EditPage(id) {
        dialog = new Overlay.Dialog({
            title: '角色管理->编辑页面',
            width: 530,
            closeAction: 'destroy',
            height: 310,
            buttons: [],
            bodyStyle: { 'padding': '0px' },
            bodyContent: '<iframe frameborder="0" style="width:520px;height:248px" src="/Admin/RoleManage/EditRole/' + id + '"></iframe>'
        });
        dialog.show();
    }

    function DeletePage(id) {
        if (confirm('确定删除？')) {
            $.ajax({
                type: 'post',
                url: '/Admin/RoleManage/DeleteRole/' + id,
                success: function (res) {
                    if (res == "0")
                        location.reload();
                    else if (res == "1")
                        alert("该角色下存在用户");
                    else if (res == "2")
                        alert("该角色下设置了权限控制");
                }
            })
        }
    }
    function SubmitSuccess() {
        dialog.close();
        location.reload();
    }
    function CloseWin() {
        dialog.close();
    }
</script>

